package com.asset.dispoal.business.bsAssetInstitutionBatch.service.converter;

import com.asset.dispoal.business.bsAssetInstitutionBatch.domain.db.entity.BsAssetInstitutionBatch;
import com.asset.dispoal.business.bsAssetInstitutionBatch.dto.BsAssetInstitutionBatchRequest;
import com.asset.dispoal.business.bsAssetInstitutionBatch.dto.BsAssetInstitutionBatchResponse;
import com.asset.dispoal.business.bsAssetInstitutionBatch.dto.BsAssetInstitutionPolicyRequest;
import com.asset.dispoal.business.bsAssetInstitutionBatch.dto.BsAssetInstitutionPolicyResponse;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author qr
 * @date 2022/3/10$
 */
@Mapper
public interface BsAssetInstitutionBatchConverter {

    BsAssetInstitutionBatchConverter INSTANCE = Mappers.getMapper(BsAssetInstitutionBatchConverter.class);


    BsAssetInstitutionBatch resToDo(BsAssetInstitutionBatchRequest request);

    default BsAssetInstitutionBatch resToDOPo(BsAssetInstitutionPolicyRequest request) {
        if (request == null) {
            return null;
        }

        BsAssetInstitutionBatch bsAssetInstitutionBatch = new BsAssetInstitutionBatch();

        bsAssetInstitutionBatch.setId(request.getId());
        if (request.getPrincipalMaxScale() != null) {
            bsAssetInstitutionBatch.setPrincipalMaxScale(new BigDecimal(request.getPrincipalMaxScale()).setScale(4, BigDecimal.ROUND_HALF_DOWN));
        }
        if (request.getInterestMaxScale() != null) {
            bsAssetInstitutionBatch.setInterestMaxScale(new BigDecimal(request.getInterestMaxScale()).setScale(4, BigDecimal.ROUND_HALF_DOWN));
        }
        if (request.getPenaltyMaxScale() != null) {
            bsAssetInstitutionBatch.setPenaltyMaxScale(new BigDecimal(request.getPenaltyMaxScale()).setScale(4, BigDecimal.ROUND_HALF_DOWN));
        }
        bsAssetInstitutionBatch.setMaxPeriod(request.getMaxPeriod());
        bsAssetInstitutionBatch.setContent(request.getContent());

        return bsAssetInstitutionBatch;
    }

    ;

    List<BsAssetInstitutionBatchResponse> doToRes(List<BsAssetInstitutionBatch> bsAssetInstitutionBatchList);

    default BsAssetInstitutionPolicyResponse doToRes(BsAssetInstitutionBatch bsAssetInstitutionBatch) {
        if (bsAssetInstitutionBatch == null) {
            return null;
        }

        BsAssetInstitutionPolicyResponse bsAssetInstitutionPolicyResponse = new BsAssetInstitutionPolicyResponse();

        bsAssetInstitutionPolicyResponse.setId(bsAssetInstitutionBatch.getId());
        if (bsAssetInstitutionBatch.getPrincipalMaxScale() != null) {
            bsAssetInstitutionPolicyResponse.setPrincipalMaxScale(bsAssetInstitutionBatch.getPrincipalMaxScale().setScale(4, BigDecimal.ROUND_HALF_DOWN).toPlainString());
        }
        if (bsAssetInstitutionBatch.getInterestMaxScale() != null) {
            bsAssetInstitutionPolicyResponse.setInterestMaxScale(bsAssetInstitutionBatch.getInterestMaxScale().setScale(4, BigDecimal.ROUND_HALF_DOWN).toPlainString());
        }
        if (bsAssetInstitutionBatch.getPenaltyMaxScale() != null) {
            bsAssetInstitutionPolicyResponse.setPenaltyMaxScale(bsAssetInstitutionBatch.getPenaltyMaxScale().setScale(4, BigDecimal.ROUND_HALF_DOWN).toPlainString());
        }
        bsAssetInstitutionPolicyResponse.setMaxPeriod(bsAssetInstitutionBatch.getMaxPeriod());
        bsAssetInstitutionPolicyResponse.setContent(bsAssetInstitutionBatch.getContent());

        return bsAssetInstitutionPolicyResponse;
    }

    ;
}
